﻿using System;
using AutoMapper;

namespace mForum.Infrastructure.AutoMapper
{
    using mForum.Domain.DomainObject;
    using mForum.Core.DataTransferObject;

    public class DefaultProfile : Profile
    {
        public override string ProfileName
        {
            get
            {
                return "DefaultProfile";
            }
        }

        protected override void Configure()
        {
            #region User entity mappings

            //mapping from Entity to DTO
            Mapper.CreateMap<User, UserDTO>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
                .ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.Password))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dest => dest.PasswordAnswer, opt => opt.MapFrom(src => src.PasswordAnswer))
                .ForMember(dest => dest.PasswordQuestion, opt => opt.MapFrom(src => src.PasswordQuestion))
                .ForMember(dest => dest.isLockedOut, opt => opt.MapFrom(src => src.isLockedOut))
                .ForMember(dest => dest.LastActivityDate, opt => opt.MapFrom(src => src.LastActivityDate))
                .ForMember(dest => dest.LastLockedOutDate, opt => opt.MapFrom(src => src.LastLockedOutDate))
                .ForMember(dest => dest.LastLoginDate, opt => opt.MapFrom(src => src.LastLoginDate))
                .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate));

            Mapper.CreateMap<User, RegisterDTO>()
                .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
                .ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.Password))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dest => dest.PasswordAnswer, opt => opt.MapFrom(src => src.PasswordAnswer))
                .ForMember(dest => dest.PasswordQuestion, opt => opt.MapFrom(src => src.PasswordQuestion));

            //mapping from DTO to Entity
            Mapper.CreateMap<UserDTO, User>()
                .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
                .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
                .ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.Password))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dest => dest.PasswordAnswer, opt => opt.MapFrom(src => src.PasswordAnswer))
                .ForMember(dest => dest.PasswordQuestion, opt => opt.MapFrom(src => src.PasswordQuestion))
                .ForMember(dest => dest.isLockedOut, opt => opt.MapFrom(src => src.isLockedOut))
                .ForMember(dest => dest.LastActivityDate, opt => opt.MapFrom(src => src.LastActivityDate))
                .ForMember(dest => dest.LastLockedOutDate, opt => opt.MapFrom(src => src.LastLockedOutDate))
                .ForMember(dest => dest.LastLoginDate, opt => opt.MapFrom(src => src.LastLoginDate))
                .ForMember(dest => dest.CreatedDate, opt => opt.MapFrom(src => src.CreatedDate));

            Mapper.CreateMap<RegisterDTO, User>()
                .ForMember(dest => dest.Username, opt => opt.MapFrom(src => src.Username))
                .ForMember(dest => dest.Password, opt => opt.MapFrom(src => src.Password))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.Email))
                .ForMember(dest => dest.PasswordAnswer, opt => opt.MapFrom(src => src.PasswordAnswer))
                .ForMember(dest => dest.PasswordQuestion, opt => opt.MapFrom(src => src.PasswordQuestion));

            #endregion
        }
    }
}
